{% extends 'base.html' %}
{% block self_head_css_js %}
    <script src="/static/layer/layer.js"></script>
{% endblock %}
{% block content %}
<script>
    window.onload=init;
    function init() {
        showhide(2);
    }
    function showhide(n) {
        var box = document.getElementById("cmdb");
        box.className="active";
        var box2 = document.getElementById("cabinet");
        box2.className="active";
    }
</script>


<div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
    </section>

    <!-- Main content -->
    <section class="content">
        <form action="{% url 'cabinet_del' %}" method="post">
                {% csrf_token %}
            <div class="box">
                <div class="box-header">
                    <div class="btn-group">
						 <a id="cabinetadd" style="display: none" class="btn btn-success" href="{% url 'cabinet_add' %}">添加机柜</a>
                  </div>
                </div>
                <!-- /.box-header -->
                <div class="box-body">
                  <table class="table table-striped table-bordered" id="dataform">
                      <thead>
                        <tr>
                            <th>
                                <input type="checkbox" onclick="checkAll(this, 'item1');" />
                            </th>
                                    <th>机柜</th>
                                    <th>描述</th>
                                    <th>操作</th>
                                </tr>
                            </thead>
                            <tbody>
                                {% if allcabinet %}
                                {% for g in allcabinet %}
                                    <tr class="even gradeA">
                                        <td><input type="checkbox" id="u_id" class="item1" value="{{ g.id }}" name="g_check" /></td>
                                        <td><a href="#"><li style="list-style-type:none" onclick="return popWin(this.value)" value="{{ g.id }}">{{ g.name }}</li></a> </td>
                                        <td>{{ g.desc }}</td>

                                        <td>
                                            <a id="cabinetedit" style="display: block; float:left; margin: auto;" href="{% url "cabinet_edit" g.id %}"><span class="btn btn-sm btn-info">编辑</span></a>
                                            <a id="cabinetdel" style="display: block; float:left; margin: auto;" href="{% url "cabinet_del"%}?id={{ g.id }}" onclick="return confirm('确认删除？')"><span class="btn btn-sm btn-danger ">删除</span></a>
                                        </td>
                                    </tr>
                                {% endfor %}
                                {% else %}
                                    <p>No Item are available.</p>
                                {% endif %}
                            </tbody>
                  </table>
                    <div class="btn-group">
						 <button id="cabinetdel" style="display: none" class="btn btn-danger " onclick="return checkSubmit()">删除机柜</button>
                    </div>
                </div>
            </div>
        </form>

    </section>
        <!-- /.content -->
      </div>
{#接收子层回传参数#}
<input id="handle_status" value="" hidden="hidden">
<script>
function checkAll(sender, checkClass) {
    var checkItems = document.getElementsByTagName('input');
    for (var i = 0; i < checkItems.length; i++) {
        var checkItem = checkItems[i];
        if (checkItem.type === 'checkbox' && checkItem.className === 'item1') {
            checkItem.checked = sender.checked;
        }
    }
}
</script>
<script src="/static/plugins/datatables/jquery.dataTables.min.js"></script>
<script src="/static/plugins/datatables/dataTables.bootstrap.min.js"></script>
<script>
  $(function () {
{#    $("#example1").DataTable();#}
    $('#dataform').DataTable({
      "paging": true,
      "lengthChange": true,
      "searching": true,
      "ordering": true,
      "info": true,
      "bAutoWidth": false
    });
  });
</script>
<script>
function checkSubmit() {
    if (!confirm("确定删除？")) {
        window.event.returnValue = false;
    }
}
</script>
<script>
function popWin(cabinet_id){
  layer.open({
      type: 2,
      title: '服务器列表',
      area: ['700px', '500px'],
      shadeClose: true, //点击遮罩关闭
      content: ['/cmdb/cabinetserverlist/' + cabinet_id]
  });
}
</script>
{% endblock %}
